﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Thu Vien Them Vao
using QuanLyQuanCafe.BusinessLogic;
using QuanLyQuanCafe.BusinessObject;

namespace QuanLyQuanCafe
{
    public partial class FrmTraCuuKhachHang : Form
    {
        private KhachHangBL khachhangBL = new KhachHangBL();
        public FrmTraCuuKhachHang()
        {
            InitializeComponent();
        }

        private void FrmTraCuuKhachHang_Load(object sender, EventArgs e)
        {
           dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayDanhSachTraCuuKhachHang();

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            }   
        }

        private KhachHangBO LayThongTinKhachHang()
        {
            KhachHangBO khachhangBO = new KhachHangBO();
            khachhangBO.CMND_KH = txtCMND_KH.Text;
            khachhangBO.HoTen = txtHoTen.Text;           
            khachhangBO.GioiTinh = txtGioiTinh.Text;
            khachhangBO.DiaChi = txtDiaChi.Text;            

            return khachhangBO;
        }

        private void txtHoTen_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
            dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void txtCMND_KH_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
           dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void txtNamSinh_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
           dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void txtGioiTinh_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
          dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void txtDiaChi_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
          dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void txtTongNo_TextChanged(object sender, EventArgs e)
        {
            KhachHangBO khachhangBO = LayThongTinKhachHang();
            string namsinhKH = txtNamSinh.Text;
            string tongnoKH = txtTongNo.Text;
         dataGridViewTraCuKhachHang.DataSource = khachhangBL.LayKetQuaDanhSachTraCuuKhachHang(khachhangBO, namsinhKH, tongnoKH);

            for (int i = 0; i < dataGridViewTraCuKhachHang.Rows.Count - 1; i++)
            {
                dataGridViewTraCuKhachHang.Rows[i].Cells["colSTT"].Value = i + 1;
            } 
        }

        private void btnHuyTraCuu_Click(object sender, EventArgs e)
        {
            txtCMND_KH.Text = "";
            txtHoTen.Text = "";
            txtNamSinh.Text = "";
            txtGioiTinh.Text = "";
            txtDiaChi.Text = "";
            txtTongNo.Text = "";
        }
    }
}
